package com.app.service.Impl;

import com.alibaba.fastjson.JSONArray;
import com.app.model.Yonghu;
import com.app.mapper.YonghuMapper;
import com.app.service.IYonghuService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yoominic
 * @since 2025-02-27
 */
@Service
public class YonghuServiceImpl extends ServiceImpl<YonghuMapper, Yonghu> implements IYonghuService {

    @Override
    public IPage<Yonghu> adminPage(Page<Yonghu> fwPage, String name) {
        IPage<Yonghu> page = this.baseMapper.adminPage(fwPage, name);
        for (Yonghu yonghu : page.getRecords()){
            String familyMembersJsonStr = yonghu.getFamilyMembersJsonStr();
            if (familyMembersJsonStr != null && !familyMembersJsonStr.equals("")){
                JSONArray array = JSONArray.parseArray(familyMembersJsonStr);
                yonghu.setFamilyMembersJson(array);
                yonghu.setFamilyMembersSize(array.size());
            }

        }
        return page;
    }
}
